package com.hyperfix.washer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyperfix.models.common.R;
import com.hyperfix.models.washer.dtos.RecordDTO;
import com.hyperfix.models.washer.dtos.RiskRecordDTO;
import com.hyperfix.models.washer.dtos.RiskRecordStatistic;
import com.hyperfix.models.washer.vos.RiskRecordQueryVO;
import com.hyperfix.washer.service.RiskRecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Min;

/**
 * @author JiangChunYu
 * 2024/4/28
 */
@Validated
@RestController
@RequestMapping("/riskRecord")
public class RiskRecordController {
    @Resource
    private RiskRecordService riskRecordService;

    /**
     * 查询历史风险数据
     *
     * @param pageNum       页码
     * @param size          大小
     * @param riskRecordQueryVO 记录查询 VO
     * @return {@link R}<{@link IPage}<{@link RecordDTO}>> 查询结果
     */
    @PostMapping("/list/{pageNum}/{size}")
    public R<IPage<RiskRecordDTO>> list(@PathVariable @Min(value = 1, message = "页号最小不能小于1") Integer pageNum,
                                        @PathVariable @Min(value = 1, message = "页大小最小不能小于1") Integer size,
                                        @RequestBody @Validated RiskRecordQueryVO riskRecordQueryVO) {
        IPage<RiskRecordDTO> riskRecordDTOIPage = riskRecordService.list(pageNum, size, riskRecordQueryVO);
        return R.success(riskRecordDTOIPage);
    }

    /**
     * 统计风险记录
     * @return {@link R}<{@link RiskRecordStatistic}> 统计结果
     */
    @PostMapping("/statistic")
    public R<RiskRecordStatistic> statistic() {
        Integer dayRiskRecordNum = riskRecordService.statisticDay();
        Integer weekRiskRecordNum = riskRecordService.statisticWeek();
        RiskRecordStatistic riskRecordStatistic = RiskRecordStatistic.builder()
                .dayRiskRecordNum(dayRiskRecordNum)
                .weekRiskRecordNum(weekRiskRecordNum)
                .build();
        return R.success(riskRecordStatistic);
    }
}
